package com.zte.purchase.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.purchase.dao.IFirmDao;
import com.zte.purchase.model.CFirm;
import com.zte.purchase.model.FirmCondition;
import com.zte.purchase.server.IFirmServer;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FirmServer implements IFirmServer {

    @Autowired
    private IFirmDao firmDao;


    @Override
    public boolean addProductFirm(CFirm firm) {
        return firmDao.addProductFirm(firm);
    }

    @Override
    public boolean updateProductFirm(CFirm cFirm) {
        return firmDao.updateProductFirm(cFirm);
    }

    @Override
    public CFirm findOneFirm(String firmId) {
        return firmDao.findOneFirm(firmId);
    }

    @Override
    public PageModel<CFirm> queryFirmList(PageModel<CFirm> pageModel, FirmCondition conn) {
        int pageNum = pageModel.getPageNum()<=1?1:pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum,pageSize);

        List<CFirm> cFirms = firmDao.queryFirmList(conn);
        PageInfo<CFirm> info = new PageInfo<>(cFirms);
        return PageModel.getPageModel(pageModel,info);
    }
}
